//app.js
App({
  onLaunch: function (opt) {
    console.log('onLaunch: ', opt)
    console.log('getLaunchOptionsSync: ', mp.getLaunchOptionsSync())
    // 展示本地存储能力
    var logs = mp.getStorageSync('logs') || []
    logs.unshift(Date.now())
    mp.setStorageSync('logs', logs)
    // 登录
    // mp.login({
    //   success: res => {
       
    //   }
    // })
    // 获取用户信息
    mp.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          mp.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })

    mp.onAppShow((res) => {
      console.log('onAppShow', res);
    })
    mp.onAppHide((res) => {
      console.log('onAppHide', res);
    })

    mp.onCustomEvent((res)=>{
      if(res.name == 'saveFileToAppletTemp') {
        const path = res.path
        console.log('~~~~saveFileToAppletTemp'+path)
        mp.showToast({
          title: 'saveFileToAppletTemp',
          icon: 'success',
          image: path,
          duration: 1500,
          mask: false,
          success (res) {
            
          },
          fail (res) {},
          complete (res) {}
        })
      } else if(res.name == 'showPageShotImage') {
        const path = res.path
        console.log('~~~~showPageShotImage'+path)
        mp.showToast({
          title: 'showPageShotImage',
          icon: 'success',
          image: path,
          duration: 1500,
          mask: false,
          success (res) {
            
          },
          fail (res) {},
          complete (res) {}
        })
      }
    })

    mp.onUnhandledRejection((res)=>{
      console.log('onUnhandledRejection', res);
    })

    mp.onError((res)=>{
      console.log('onError', res);
    })

    mp.onPageNotFound((res)=>{
      console.log('onPageNotFound', res);
    })
  },
  globalData: {
    userInfo: null
  }
})